package SimulatorComponents;

import ControlComponents.ALU;
import ControlComponents.ControlUnit;
import ControlComponents.InstructionRegister;
import ControlComponents.ProgramCounter;
import ControlComponents.StatusRegister;
import Peripherals.IODeviceController;
import StorageComponents.Accumulator;
import StorageComponents.Memory;
import StorageComponents.Registers;

/**
 * 
 * Specifications for a simple RISC computer object. This class only holds reference to all its components, 
 * but does not perform any operations on them, except for method start()
 *
 */
public class AR2RISC {
	private Memory mem;
	private InstructionRegister ir;
	private StatusRegister sr;
	private ProgramCounter pc;
	private Registers regs;
	private Accumulator acc;
	private ControlUnit controlUnit;
	private ALU alu;
	private IODeviceController io;
	
	
	public AR2RISC(int mode){
		
		mem = new Memory();
		ir = new InstructionRegister();
		sr = new StatusRegister();
		pc = new ProgramCounter();
		regs = new Registers();
		acc = new Accumulator();
		alu = new ALU(sr, acc);
		io = new IODeviceController();
		controlUnit = new ControlUnit(mem, ir, sr, pc, regs, acc, alu, io, mode);
		
		System.out.println( "AR2RISC PC VALUE " + pc.getIntValue() );
	}


	/**
	 * Method begins the first fetch execute cycle by calling the fetch() method on object the ControlUnit object
	 */
	public void start(){
			controlUnit.fetch();
	
	}

	/**
	 * Returns the memory component 
	 * @return the memory component
	 */
	public Memory getMem() {
		return mem;
	}

	/**
	 * Returns the instruction register component 
	 * @return the instruction register component
	 */
	public InstructionRegister getIr() {
		return ir;
	}

	/**
	 * Returns the status register component 
	 * @return the status register component
	 */
	public StatusRegister getSr() {
		return sr;
	}

	/**
	 * Returns the program counter component 
	 * @return the program counter component
	 */
	public ProgramCounter getPc() {
		return pc;
	}

	/**
	 * Returns the general register component 
	 * @return the general register component
	 */
	public Registers getRegs() {
		return regs;
	}

	/**
	 * Returns the accumulator component 
	 * @return the accumulator component
	 */
	public Accumulator getAcc() {
		return acc;
	}

	/**
	 * Returns the control component 
	 * @return the control component
	 */
	public ControlUnit getControlUnit() {
		return controlUnit;
	}
}
